<?php

namespace App\Http\Controllers\Common;

use Illuminate\Foundation\Http\FormRequest;

class FileRequest extends FormRequest
{

    public $fileMaxSize = 102400;

    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    public function __construct(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null)
    {
        parent::__construct($query, $request, $attributes, $cookies, $files, $server, $content);

        $this->fileMaxSize = config('cdyz.file.maxSize');
    }

    public function rules()
    {
        $mime = implode(',', config('cdyz.file.mime_type'));

        $rule = [
            'file.*' => "required|mimetypes:{$mime}|max:{$this->fileMaxSize}"
        ];

        return $rule;

    }


    public function messages()
    {

        $message =  [
            'file.required' => '请上传文件',
            'file.mimetypes' => '只能上传word,excel,pdf,图片',
            'file.max' => "文件大小超过{$this->fileMaxSize}kb"
        ];

        return $message;
    }


}
